package com.example.education.Controller;


import com.example.education.Bean.CollegeSubjects;
import com.example.education.Bean.StudentInfo;
import com.example.education.Bean.packaginggroup.PackagingString;
import com.example.education.Mapper.CollegeSubjectsMapper;
import com.example.education.service.CollegeSubjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.Cacheable;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/collegesubjects")
@CrossOrigin
public class CollegeSubjectsController {

    @Autowired
    private CollegeSubjectsMapper collegeSubjectsMapper;
    @Autowired
    private CollegeSubjectsService collegeSubjectsService;

    //增
    @PostMapping
    public Integer save(@RequestBody(required = false) CollegeSubjects collegeSubjects) {//将传回来的json对象转

        return collegeSubjectsService.insert(collegeSubjects);
    }

    //根据学校名字查找学校的所有专业
    @PostMapping("/select")
    @Cacheable(value = "collegeSubjects")
    public ArrayList<CollegeSubjects> select(@RequestBody(required = false) PackagingString packageString) {
        ArrayList<CollegeSubjects> collegeSubjects = collegeSubjectsService.select(packageString.getString());
        System.out.println("__________________" + collegeSubjects);
        return collegeSubjects;
    }


    //推荐学校
    @PostMapping("/find")
    public ArrayList<CollegeSubjects> find(@RequestBody(required = false) StudentInfo studentInfo) {
        System.out.println(studentInfo);
        ArrayList<CollegeSubjects> list = collegeSubjectsService.find(studentInfo);
        System.out.println(list);
        return list;
    }
}

